package com.teamone.monopoly.domain;

import java.util.ArrayList;
import java.util.List;

public class MGame {

	public static final int NUMBER_OF_PLAYERS = 2;
	public static final float INITIAL_PLAYER_CASH = 1500;
	private int currRound;
	List<Player> players = new ArrayList<Player>(NUMBER_OF_PLAYERS);
	List<String> turnResults = new ArrayList<String>();
	int numRounds;
	Board board = new Board();
	
	public MGame() {
	}

	public void play(int N, int totalNumPlayers) {
		numRounds = N;
		for (int i=0; i<totalNumPlayers; i++) {
			Player player = new Player(board, new Die(), new Die());
			player.setPosition(board.firstSquareInBoard());
			players.add(player);
		}
		
		for (int i=0; i<numRounds; i++) {
			playRound();
		}
	}

	private void playRound() {
		for (Player player : players) {
			player.takeTurn();
			turnResults.add(String.valueOf(player.getDiceTotal()));
		}
		currRound++;
	}

	public String getGameOutput() {
		if (turnResults.size() == 0) {
			return "()";
		}
		
		StringBuilder gameOutput = new StringBuilder("(");
		
		for (int i=0; i<turnResults.size()-1; i++) {
			gameOutput.append(turnResults.get(i));
			gameOutput.append(",");
		}
		gameOutput.append(turnResults.get(turnResults.size()-1));
		gameOutput.append(")");
		
		return gameOutput.toString();
	}

	public int getCurrentRound() {
		return currRound;
	}

}
